﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Text;
using System.Configuration;
public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string pretext = context.Request.QueryString["q"];
        using(SqlCommand cmd = DataAccess.Connection.CreateCommand());
        cmd.CommandText = " select pid,pname,price,picture from Product where pname like '%' + @tensp + '%'";
        cmd.Parameters.AddWithValue("@tensp",pretext);
        //cmd.Parameters.Add("@tensp", SqlDbType.NVarChar).Value = TextBox1.Text;
        StringBuilder sb = new StringBuilder();
       using( SqlDataReader dr = cmd.ExecuteReader());
        if (dr.HasRows)
        {
            if (dr.Read())
            {
                sb.Append(dr["pname"]).Append(Environment.NewLine);
            }

        }
        context.Response.Write(sb.ToString());
        //context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}